<?php
    define('ABSOLUTE_SERVER_REMOTE_ADDR','http://'.$_SERVER['HTTP_HOST'].'/');
    define('ABSOLUTE_SERVER_DOCUMENT_ROOT','../admin/');

    include(ABSOLUTE_SERVER_DOCUMENT_ROOT.'session.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'funct.inc');   
    
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style.php';

    require_once('../classDB.inc.php');
    require_once('../plugins/input/classInput.inc.php');
    require_once('../plugins/session/classSession.inc.php');
    require_once('../definitions.inc.php');
    require_once('../plugins/filesystem/classFileSystem.inc.php');
    require_once('../plugins/template/classTemplate.inc.php');
    require_once('../plugins/template/classTemplate.inc.php');
    require_once('../plugins/i18n/classI18N.inc.php');
    include LANGUAGE;

    if(!GetAdminID($ID)){echo LOGIN_ERR; exit;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>

    <title>Home screen</title>
	<style  type="text/css">
		table{
            border-bottom-color: black;
            border-top-color: black;
            border-left-color: black;
            border-right-color: black;
            border-collapse: collapse;
            font-size: 10px;
            font-family:  verdana;
        }
        form {margin-top:0pt; margin-bottom:0px;}
        img {margin-top:0pt; margin-bottom:0px;}
        body{
            margin-left:10px;
            margin-right:0pt;
            margin-top:0pt;
            margin-bottom:0pt;
            font-family:  verdana;
            font-size: 10px;
        }
        input {
            border: 1px solid black;
            cursor: pointer;
            background-color: white;
            font-size: 10px;
            margin-left: 0px;
            padding-left: 0px;
            list-style-type: none;
            font-family:  Verdana;
        }
        a {
		  	text-decoration: none; 
		  	font-weight: normal; 
		  	color:black; 
		  	font-size:10px;
		}
		a:hover {
		  	text-decoration: underline; 
			font-weight: normal; 
			color:#808080; 
			font-size:10px;
		}
    </style>
	
</head>

<?php
    print "<body bgcolor=\"".BACKGROUND_IN_TABLE."\">";

    $_DB = new classDB();
    if (!$_DB->open()){echo OPEN_DB_ERR; break;}

    $_InformationPanel = new classInformationPanel();
	
    do{
        //-----------------------------------------------------------------------------------------------
        //NADPIS
        print "<center><h4 style=\"margin-top:0pt; margin-bottom:0pt;\">".HS_HOME_SCREEN."</h4></center>";
        //-----------------------------------------------------------------------------------------------

        $_InformationPanel->Show();

        print '
            <center>
                <table cellpadding="7">
                    <tr>
                        <td style="width:105px; border: 1px dotted black; border-left:0; border-top:0;">
                            <center>
                                <a href="adm_product.php" target="place">
                                    <img src="img/home_screen/products_list.png" border="0" alt="'.H_TOVAR.'" />
                                    <br />
                                    <b>'.H_TOVAR.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-top:0;">
                            <center>
                                <a href="order_management.php" target="place">
                                    <img src="img/home_screen/orders_list.png" border="0" alt="'.H_OBJEDNAVKY.'" />
                                    <br />
                                    <b>'.H_OBJEDNAVKY.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-top:0;">
                            <center>
                                <a href="chat_management.php" target="place">
                                    <img src="img/home_screen/recieved_messages.png" border="0" alt="'.H_SPRAVY.'" />
                                    <br />
                                    <b>'.H_SPRAVY.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-right:0; border-top:0;">
                            <center>
                                <a href="modules/top_menu/categorie_creator.php" target="place">
                                    <img src="img/home_screen/top_menu.png" border="0" alt="'.H_KATEGORIE_UZIVATELSKEHO_MENU.'" />
                                    <br />
                                    <b>'.H_KATEGORIE_UZIVATELSKEHO_MENU.'</b>
                                </a>
                            </center>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:105px; border: 1px dotted black; border-left:0;">
                            <center>
                                <a href="modules/categorie_creator/categorie_creator.php" target="place">
                                    <img src="img/home_screen/products_categoryies.png" border="0" alt="'.H_TOVAR_KATEGORIE.'" />
                                    <br />
                                    <b>'.H_TOVAR_KATEGORIE.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-left:0; border-top:0;">
                            <center>
                                <a href="modules/invoice/invoice.php" target="place">
                                    <img src="img/home_screen/invoice_list.png" border="0" alt="'.H_ZOZNAM_FAKTUR.'" />
                                    <br />
                                    <b>'.H_ZOZNAM_FAKTUR.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black;">
                            <center>
                                <a href="users_management.php" target="place">
                                    <img src="img/home_screen/users_list.png" border="0" alt="'.H_UZIVATELA.'" />
                                    <br />
                                    <b>'.H_UZIVATELA.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-right:0;">
                            <center>
                                <a href="modules/top_menu/news_creator.php" target="place">
                                    <img src="img/home_screen/news.png" border="0" alt="'.H_KATEGORIE_NOVINIEK.'" />
                                    <br />
                                    <b>'.H_KATEGORIE_NOVINIEK.'</b>
                                </a>
                            </center>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:105px; border: 1px dotted black; border-bottom:0; border-left:0;">
                            <center>
                                <a href="modules/top_products/top_products.php" target="place">
                                    <img src="img/home_screen/products_statistics.png" border="0" alt="'.H_NAJPREDAVANEJSI_TOVAR.'" />
                                    <br />
                                    <b>'.H_NAJPREDAVANEJSI_TOVAR.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-bottom:0;">
                            <center>
                                <a href="modules/invoice/invoice_options.php" target="place">
                                    <img src="img/home_screen/order_invoice_settings.png" border="0" alt="'.H_NASTAVENIE_FAKTUR.'" />
                                    <br />
                                    <b>'.H_NASTAVENIE_FAKTUR.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-bottom:0;">
                            <center>
                                <a href="modules/product_link/adm_main_frame.php?Reset_Cookie=YES" target="place">
                                    <img src="img/home_screen/product_to_email.png" border="0" alt="'.H_ZOZNAM_PRODUKTOV_NA_EMAIL.'" />
                                    <br />
                                    <b>'.H_ZOZNAM_PRODUKTOV_NA_EMAIL.'</b>
                                </a>
                            </center>
                        </td>
                        <td style="width:105px; border: 1px dotted black; border-bottom:0; border-right:0;">
                            <center>
                                <a href="modules/top_menu/adm_informations_big_frame.php" target="place">
                                    <img src="img/home_screen/articles.png" border="0" alt="'.H_TEXTY_MENU_A_NOVINIEK.'" />
                                    <br />
                                    <b>'.H_TEXTY_MENU_A_NOVINIEK.'</b>
                                </a>
                            </center>
                        </td>
                    </tr>
                </table>
            </center>
        ';
    }
while(false);
mysql_close();
?>
</body>
</html>

<?php
class classInformationPanel{
    public function Show(){
        echo '
            <table style="border:1px dotted black; position:absolute; top: 10px; left: 10px;">
                <tr>
                    <td style="padding:10px; margin:10px; background-color:'.TR_BACKGOUND_COLOR_1.';">
                        '.$this->showOrderInfo().'
                    </td>
                </tr>
                <tr>
                    <td style="padding:10px; margin:10px; background-color:'.TR_BACKGOUND_COLOR_2.';">
                        '.$this->showMessagesInfo().'
                    </td>
                </tr>
                <tr>
                    <td style="padding:10px; margin:10px; background-color:'.TR_BACKGOUND_COLOR_1.';">
                        '.$this->showUsersInfo().'
                    </td>
                </tr>
                <tr>
                    <td style="padding:10px; margin:10px; background-color:'.TR_BACKGOUND_COLOR_2.';">
                        '.$this->showProductsInfo().'
                    </td>
                </tr>
            </table>
        ';
    }

    private function showOrderInfo(){
        $sql_result = mysql_query('SELECT COUNT(*) AS UnreadCount FROM order_heads WHERE OH_Unread IS NULL;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iNewOrders = $sql_obj->UnreadCount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('SELECT COUNT(*) AS UnconfirmedCount FROM order_heads WHERE OH_Confirm IS NULL;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iUncOrders = $sql_obj->UnconfirmedCount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('select NO, Order_Create from order_heads where (select max(ID) from order_heads) = ID;');
        $sql_obj    = mysql_fetch_object($sql_result);
        if(trim($sql_obj->Order_Create)=='' or is_null($sql_obj->Order_Create)){
            $sLastOrder = '-';
            //-------------------------------------------------------------
            $LODate     = '-';
            //-------------------------------------------------------------
        }
        else{
            $sLastOrder = date('Y',strtotime($sql_obj->Order_Create)).'/'.$sql_obj->NO;
            //-------------------------------------------------------------
            $LODate     = date(sttngs_DATE_FORMAT,strtotime($sql_obj->Order_Create));
            //-------------------------------------------------------------
        }
        return '
            <table cellspacing="0" cellpadding="0" style="width:100%;">
                <tr>
                    <td colspan="2">
                        <center><b><font style="font-size:12px;">'.HS_OBJDNAVKY.'</font></b></center>
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_NOVE.': </b>
                    </td>
                    <td>
                        '.$iNewOrders.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_NEPOTVRDENE.': </b>
                    </td>
                    <td>
                        '.$iUncOrders.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_CISLO_POSLEDNEJ.': </b>
                    </td>
                    <td>
                        '.$sLastOrder.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_DATUM_POSLEDNEJ.': </b>
                    </td>
                    <td>
                        '.$LODate.'
                    </td>
                </tr>
            </table>
        ';
    }
    private function showMessagesInfo(){
        $sql_result = mysql_query('SELECT COUNT(*) AS MCount FROM chat;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iMCount = $sql_obj->MCount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('select Ch_Name, Ch_Surname, Ch_Title, Ch_DateTime from chat where (select max(Ch_DateTime) from chat) = Ch_DateTime;');
        $sql_obj    = mysql_fetch_object($sql_result);
        if(trim($sql_obj->Ch_DateTime)=='' or is_null($sql_obj->Ch_DateTime)){
            $sLMDateTime= '-';
            $sLMSender  = '';
            $sLMSubject = '';
        }
        else{
            $sLMDateTime= date(sttngs_DATE_FORMAT.', '.sttngs_TIME_FORMAT,strtotime($sql_obj->Ch_DateTime));
            $sLMSender  = $sql_obj->Ch_Name.' '.$sql_obj->Ch_Surname;
            $sLMSubject = substr($sql_obj->Ch_Title,0,30);
        }
        //-------------------------------------------------------------
        return '
            <table cellspacing="0" cellpadding="0" style="width:100%;">
                <tr>
                    <td>
                        <center><b><font style="font-size:12px;">'.HS_PRIJATE_SPRAVY.'</font></b></center>
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_POCET_SPRAV.': </b> '.$iMCount.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_POSLEDNA_PRIJATA.': </b> <br />
                            '.$sLMDateTime.'<br />
                            '.$sLMSender.'<br />
                            '.$sLMSubject.'<br />
                    </td>
                </tr>
            </table>
        ';
    }
    private function showUsersInfo(){
        $sql_result = mysql_query('SELECT COUNT(*) AS UCount FROM users;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iUCount = $sql_obj->UCount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('SELECT U_Name, U_Surname FROM users WHERE (select max(ID) from users) = ID;');
        $sql_obj    = mysql_fetch_object($sql_result);
        if(trim($sql_obj->U_Surname)=='' or is_null($sql_obj->U_Surname))
            $sLastSigned = '-';
        else
            $sLastSigned = $sql_obj->U_Name.' '.$sql_obj->U_Surname;
        //-------------------------------------------------------------
        return '
            <table cellspacing="0" cellpadding="0" style="width:100%;">
                <tr>
                    <td>
                        <center><b><font style="font-size:12px;">'.HS_UZIVATELIA.'</font></b></center>
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_POCET.': </b> '.$iUCount.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_POSLEDNY_REGISTROVANY.':</b> <br />
                            '.$sLastSigned.'
                    </td>
                </tr>
            </table>
        ';
    }
    private function showProductsInfo(){
        $sql_result = mysql_query('SELECT COUNT(*) AS PCount FROM products;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iPCount = $sql_obj->PCount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('SELECT COUNT(*) AS ACount FROM product_actions;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iACount    = $sql_obj->ACount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('SELECT COUNT(*) AS ACount FROM product_actions;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iACount    = $sql_obj->ACount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('SELECT COUNT(*) AS NCount FROM product_news;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iNCount    = $sql_obj->NCount;
        //-------------------------------------------------------------
        $sql_result = mysql_query('SELECT COUNT(*) AS SCount FROM product_sale;');
        $sql_obj    = mysql_fetch_object($sql_result);
        $iSCount    = $sql_obj->SCount;
        //-------------------------------------------------------------
        return '
            <table cellspacing="0" cellpadding="0" style="width:100%;">
                <tr>
                    <td colspan="2">
                        <center><b><font style="font-size:12px;">'.HS_PRODUKTY.'</font></b></center>
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_POCET.': </b>
                    </td>
                    <td>
                        '.$iPCount.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_AKCIE.': </b>
                    </td>
                    <td>
                        '.$iACount.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_NOVINKY.': </b>
                    </td>
                    <td>
                        '.$iNCount.'
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>'.HS_VYPREDAJ.': </b>
                    </td>
                    <td>
                        '.$iSCount.'
                    </td>
                </tr>
            </table>
        ';
    }
}
?>